﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace PersonalFinances.Models
{
    public class Transaction
    {
        #region Attributes and Properties

        private int _id;
        public int ID
        {
            get { return _id; }
            set { _id = value; }
        }

        private TransactionType _type;
        public TransactionType Type
        {
            get { return _type; }
            set { _type = value; }
        }

        private int _accountID;
        public int AccountID
        {
            get { return _accountID; }
            set { _accountID = value; }
        }

        private Account _account;
        [ForeignKey("AccountID")]
        public virtual Account Account
        {
            get { return _account; }
            set { _account = value; }
        }

        private int _categoryID;
        public int CategoryID
        {
            get { return _categoryID; }
            set { _categoryID = value; }
        }

        private Category _category;
        [ForeignKey("CategoryID")]
        public virtual Category Category
        {
            get { return _category; }
            set { _category = value; }
        }

        private string _description;
        [Required(AllowEmptyStrings=false, ErrorMessage="Please enter a description")]
        public string Description
        {
            get { return _description; }
            set { _description = value; }
        }

        private DateTime _date = DateTime.Now;
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime Date
        {
            get { return _date; }
            set { _date = value; }
        }

        private float _value;
        [Required(ErrorMessage="Please enter a value")]
        public float Value
        {
            get { return _value; }
            set { _value = value; }
        }

        private bool _paid;
        public bool Paid
        {
            get { return _paid; }
            set { _paid = value; }
        }

        #endregion
    }

    public class TransactionDbContext : DbContext
    {
        public TransactionDbContext()
            : base("PersonalFinancesDbContext")
        {
        }

        public DbSet<Transaction> Transactions { get; set; }
    }
}